import { history } from 'STORE';
import ReportService from '../views/levelCReport/service/ReportService';
/**
 * 用户访问权限拦截器
 * @export {Function} onEnter，详见以下文档：
 * https://github.com/reactjs/react-router/blob/master/docs/API.md#onEnter
 */
export default function evaAuth(nextState, replace, next) {
  // let { userData } = store.getState()
  console.log(localStorage.getItem('userAuthToken'))
  if (localStorage.getItem('userAuthToken')) {
    ReportService.getRoleName().then(re => {
        let isAdmin = (re && re[0] == 'evaAdmin') ? 'true' : 'false';
        if (isAdmin == 'true') {
            return next()
        }
        else {
            alert('无权限访问')
            history.goBack()
        }
    });
  }
}
